package com.designpattern.singleton;

/**
 * @author liyanhao
 * @Date 2023-02-06 20:28
 * 饿汉式 静态代码块
 */
public class SingletonTest02 {

    public static void main(String[] args) {
        Singleton02 instance = Singleton02.getInstance();
        Singleton02 instance1 = Singleton02.getInstance();
        System.out.println(instance1 == instance);
    }
}
class Singleton02{
    private final static Singleton02 instance;

    static {
        instance = new Singleton02();
    }
    private Singleton02() {
    }

    public static Singleton02 getInstance() {
        return instance;
    }
}
